import java.util.Scanner;

public class Takeout {
	public static void main(String[] args) {
		int k;//用户输入0返回菜单
		Scanner input = new Scanner(System.in);
		String[] names = new String[4];//点餐人姓名
		String[] dishMegs = new String[4];//储存菜品信息
		int[] num = new int[4];//点餐数
		int[] times = new int[4];//订单时间
		String[] addresses = new String[4];//订单地址
		int[] states = new int[4];//订单状态
		double[] sumPrices = new double[4];//订单价格
		boolean isExit = false;


		//初始化菜名，单价，点赞数
		String[] dishNames = {"红烧带鱼", "鱼香肉丝", "时令时蔬"};
		double[] Prices = new double[]{38.0, 20.0, 10.0};
		int[] likeNum = new int[3];


		// 初始化2条订单信息
		// 第1条
		names[0] = "张晴";
		dishMegs[0] = "红烧带鱼";
		num[0] = 2;
		times[0] = 12;
		addresses[0] = "天成路207号";
		states[0] = 1;
		sumPrices[0] = 76.0;
		// 第2条
		names[1] = "张晴";
		dishMegs[1] = "鱼香肉丝";
		times[1] = 18;
		addresses[1] = "天成路207号";
		states[1] = 0;
		sumPrices[1] = 45.0;
		num[1] = 1;

		//实现菜单切换
		do {
			System.out.println("欢迎使用“吃货联盟订餐系统”");
			System.out.println("************************************");
			System.out.println("1.我要订餐");
			System.out.println("2.查看餐袋");
			System.out.println("3.签收订单");
			System.out.println("4.删除订单");
			System.out.println("5.我要点赞");
			System.out.println("6.退出系统");
			System.out.println("************************************");
			System.out.print("请输入选项：");
			k = input.nextInt();
			switch (k) {
				case 1:
					//我要订餐
					System.out.println("***我要订餐***");
					boolean dingCan = false;//记录是否可订餐
					for (int a = 0; a < names.length; a++) {

						if (names[a] == null) {
							dingCan = true;  //可以订餐

							System.out.print("请输入订餐人姓名：");
							String name = input.next();
							System.out.println("序号\t菜名\t\t单价\t\t点赞数");
							for (int b = 0; b < dishNames.length; b++) {
								System.out.println((b + 1) + "\t\t" + dishNames[b] + "\t\t" + Prices[b] + "元\t\t" + likeNum[b]);
							}
							System.out.print("请选择您要点的菜品编号：");
							int choose = input.nextInt();
							System.out.print("请选择您需要的份数：");
							int num1 = input.nextInt();
							double price = num1 * Prices[choose - 1];
							String dishmeg = dishNames[choose - 1];
							System.out.print("请输入送餐时间（送餐时间是10点至20点之间的整点送餐）：");
							int time = input.nextInt();
							if (time < 10 || time > 20) {
								System.out.print("您的输入有误，请重新输入：");
								time = input.nextInt();
							}
							System.out.print("请输入送餐地址：");
							String dress = input.next();
							double pei;
							if (Prices[choose - 1] * num1 > 50) {
								pei = 0;
							} else {
								pei = 5;
							}
							System.out.println("订单成功");
							System.out.println("您订的是：" + dishNames[choose - 1] + " " + num1 + "份");
							System.out.println("送餐时间是：" + time + "点");
							System.out.println("餐费：" + price + "元 配送费为：" + pei + "元 总计为：" + (price + pei) + "元");

							names[a] = name;
							dishMegs[a] = dishmeg;
							times[a] = time;
							addresses[a] = dress;
							sumPrices[a] = price + pei;
							states[a] = 0;
							num[a] = num1;
							break;
						}
					}
					if (!dingCan) {
						System.out.println("对不起，您的餐袋已满。");
					}
					break;
				case 2:
					//查看餐袋
					System.out.println("***查看餐袋***");
					System.out.println("序号\t订餐人\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t\t\t\t\t总金额\t\t订单状态");
					for (int c = 0; c < names.length; c++) {
						if (names[c] != null) {
							String state = (states[c] == 0) ? "已预订" : "已完成";
							System.out.println((c + 1) + "\t\t" + names[c] + "\t" + dishMegs[c] + "\t\t" + num[c] + "份\t\t\t" + times[c] + "点\t\t\t" + addresses[c] + "\t\t\t\t\t\t" + sumPrices[c] + "元\t\t" + state);
						}
					}
					break;
				case 3:
					//签收订单
					System.out.println("***签收订单***");
					System.out.println("请输入您要签收的订单编号：");
					int custNo = input.nextInt();
					if (names[custNo - 1] != null && states[custNo - 1] == 0) {
						states[custNo - 1] = 1;
						System.out.println("您的订单签收成功");
					} else
						System.out.println("未查询到相应订单，签收失败，请确认订单信息是否已签收。");
					break;

				case 4:
					//删除订单
					System.out.println("请输入您要删除的订单号：");
					int delete = input.nextInt();
					boolean isFind = false;
					for (int i = 0; i < names.length; i++) {
						if (names[i] != null && states[i] == 1 && delete == i + 1) {
							isFind = true;
							for (int j = delete - 1; j < names.length - 1; j++) {
								names[j] = names[j + 1];
								dishMegs[j] = dishMegs[j + 1];
								num[j] = num[j + 1];
								times[j] = times[j + 1];
								addresses[j] = addresses[j + 1];
								states[j] = states[j + 1];
								sumPrices[j] = sumPrices[j + 1];
							}
							names[names.length - 1] = null;
							dishMegs[names.length - 1] = null;
							num[names.length - 1] = 0;
							times[names.length - 1] = 0;
							addresses[names.length - 1] = null;
							states[names.length - 1] = 0;
							sumPrices[names.length - 1] = 0;
							System.out.println("删除订单成功！");
							break;
						} else if (names[i] != null && states[i] == 0 && delete == i + 1) {
							isFind = true;
							System.out.println("您选择的订单未签收，不能删除！");
							break;
						}
					}
					if (!isFind) {
						System.out.println("您要删除的订单不存在！");
					}
					break;
				case 5:
					//我要点赞
					System.out.println("***我要点赞***");
					// 显示菜品信息
					System.out.println("序号\t菜名\t单价");
					for (int i = 0; i < dishNames.length; i++) {
						String dianzan = (likeNum[i] > 0) ? likeNum[i] + "赞" : "";
						System.out.println((i + 1) + "\t" + dishNames[i] + "\t" + Prices[i] + "元" + dianzan);
					}
					System.out.print("请选择您要点赞的菜品序号：");
					int number = input.nextInt();
					likeNum[number - 1]++;
					System.out.println("点赞成功");
					break;
				default:
					isExit = true;
					break;

			}
			if (isExit) {
				break;
			}
			System.out.print("输入0返回：");
			int i = input.nextInt();
			if (i == 0) {
				k = 0;
			}
		} while (k == 0);
		System.out.println("感谢您的使用，欢迎下次光临。");
	}
}
